import redis


#定义ip地址和端口
host = "127.0.0.1"
port = 6379

#生成链接对象
r = redis.Redis(host=host,port=port)

# r.set('test','test')

# mytest = r.get('test')
# #打印 b'test'

# #转码
# mytest = mytest.decode('utf-8')

# print(mytest)
# #打印 test

# r.sadd("testset","爆款")
# r.sadd("testset","修身")

# r.zadd('myrank',{'car':100})
r.zadd('myrank',{'phone':30})

#修改操作
newscore = r.zincrby('myrank',-300,'phone')
print(newscore)

#遍历有序集合
print(r.zrange('myrank',0,-1,desc=True,withscores=True))

#赋值
myrank = r.zrange('myrank',0,-1,desc=True,withscores=True)
# r.expire('myrank',60)
# print(r.ttl("myrank"))
#取值  强转字符串  
print(str(myrank[0][0],'utf-8'))  

# #查询
# myset = r.smembers("testset")
# print(myset)
# myset = list(myset)
# mytag = str(myset[0],"utf-8")
# print(mytag)

#生命周期
# r.set('123','123') 
# r.expire('123',10)
# print(r.get('123'))
